package com.ithuangyl.common.net;

import android.content.Context;

import com.ithuangyl.common.loader.LoaderStyle;
import com.ithuangyl.common.net.callback.IError;
import com.ithuangyl.common.net.callback.IFailure;
import com.ithuangyl.common.net.callback.IRequest;
import com.ithuangyl.common.net.callback.ISuccess;

import java.util.HashMap;

/**
 * author : itHuang
 * e-mail : ithuangyl@163.com
 * date   : 2020/7/15 21:44
 */
public class RestClientBuilder {

    private HashMap<String, Object> params = new HashMap<>();
    private String url;
    private Class<?> clazz;
    private IRequest request;
    private ISuccess<?> success;
    private IFailure failure;
    private IError error;
    private Context context;
    private LoaderStyle loaderStyle;

    public RestClient build() {
        return new RestClient(url, params, clazz, request, success, failure, error, context, loaderStyle);
    }

    public RestClientBuilder url(String url) {
        this.url = url;
        return this;
    }

    public RestClientBuilder params(HashMap<String, Object> params) {
        this.params.putAll(params);
        return this;
    }

    public RestClientBuilder param(String key, Object param) {
        this.params.put(key, param);
        return this;
    }


    public RestClientBuilder clazz(Class<?> clazz) {
        this.clazz = clazz;
        return this;
    }

    private RestClientBuilder request(IRequest request) {
        this.request = request;
        return this;
    }

    public RestClientBuilder success(ISuccess<?> success) {
        this.success = success;
        return this;
    }

    public RestClientBuilder failure(IFailure failure) {
        this.failure = failure;
        return this;
    }

    public RestClientBuilder error(IError error) {
        this.error = error;
        return this;
    }

    public RestClientBuilder loaderStyle(Context context, LoaderStyle loadStyle) {
        this.context = context;
        this.loaderStyle = loadStyle;
        return this;
    }
}
